package com.pine.dcts.websocket;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * 消息发送监听事件
 *
 * @author xiaoyuan
 * @create 2020/10/14 14:19
 **/
@Component
public class SendMessageListener implements ApplicationListener<SendMessageEvent> {
    @Autowired
    private WebSocketHandler webSocketHandler;


    @Override
    public void onApplicationEvent(SendMessageEvent sendMessageEvent) {
        WebSocketMessage message = (WebSocketMessage) sendMessageEvent.getSource();
        if (StringUtils.isNotEmpty(message.getMessage()))
        { webSocketHandler.sendMessage(message.getKey(),message.getMessage());}
    }
}
